package edu.corn.job.core.processor.adapter.factory;

import edu.corn.job.core.engine.JobEngine;
import edu.corn.job.core.processor.AbstractCompositeJob;
import edu.corn.job.core.processor.AbstractJobProcessor;
import edu.corn.job.core.processor.AbstractPhaseJobProcessor;
import edu.corn.job.core.processor.adapter.CompositeJopAdapter;
import edu.corn.job.core.processor.adapter.JobAdapter;
import edu.corn.job.core.processor.adapter.PhaseJobAdapter;

public class JobAdapterFactory {


    /**
     * 根据传入的job类型，返回对应的job处理器。
     *
     * @param processor
     * @return
     */
    public static JobAdapter getAdapter(AbstractJobProcessor processor, JobEngine jobEngine) {
        if (processor instanceof AbstractCompositeJob)
            return new CompositeJopAdapter(processor, jobEngine);
        else if (processor instanceof AbstractPhaseJobProcessor)
            return new PhaseJobAdapter(processor, jobEngine);
        throw new UnsupportedOperationException();
    }

}
